<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="6">
            <a-form-model-item label="条形码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barcode">
              <a-input v-model="model.barcode" placeholder="请输入条形码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialId">
              <a-input v-model="model.materialId" placeholder="请输入物料编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialName">
              <a-input v-model="model.materialName" placeholder="请输入物料名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="物料规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialSpec">
              <a-input v-model="model.materialSpec" placeholder="请输入物料规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="物料批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNo">
              <a-input v-model="model.batchNo" placeholder="请输入物料批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="供应商批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierBatchNo">
              <a-input v-model="model.supplierBatchNo" placeholder="请输入供应商批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="备用批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNoReserve">
              <a-input v-model="model.batchNoReserve" placeholder="请输入备用批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="produceDate">
              <j-date placeholder="请选择生产日期"  v-model="model.produceDate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="生产商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manufacturer">
              <a-input v-model="model.manufacturer" placeholder="请输入生产商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="失效日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expirationDate">
              <j-date placeholder="请选择失效日期"  v-model="model.expirationDate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplier">
              <a-input v-model="model.supplier" placeholder="请输入供应商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meUnit">
              <a-input v-model="model.meUnit" placeholder="请输入主单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="辅单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auUnit">
              <a-input v-model="model.auUnit" placeholder="请输入辅单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meQuantity">
              <a-input-number v-model="model.meQuantity" placeholder="请输入入库数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库辅数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auQuantity">
              <a-input-number v-model="model.auQuantity" placeholder="请输入入库辅数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instockBillNo">
              <a-input v-model="model.instockBillNo" placeholder="请输入入库单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库明细ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instockDetailId">
              <a-input v-model="model.instockDetailId" placeholder="请输入入库明细ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库库位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instockLocator">
              <a-input v-model="model.instockLocator" placeholder="请输入入库库位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instockDate">
              <j-date placeholder="请选择入库时间"  v-model="model.instockDate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="质检时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qualityCheckDate">
              <j-date placeholder="请选择质检时间"  v-model="model.qualityCheckDate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="条形码状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barcodeStatus">
              <a-input v-model="model.barcodeStatus" placeholder=""  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="入库类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instockType">
              <a-input v-model="model.instockType" placeholder="请输入入库类型"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TslWmBarcodeForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           barcode: [
              { required: true, message: '请输入条形码!'},
           ],
        },
        url: {
          add: "/barcode/tslWmBarcode/add",
          edit: "/barcode/tslWmBarcode/edit",
          queryById: "/barcode/tslWmBarcode/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>